<?php

namespace Common\Model;
use think\Model;

class UserTuanModel extends BaseModel{

	//追加属性
    public $append = [
        'add_time_text',
        'status_text',
        'sub_num',//提交数量
	];

    public function getSubNumAttr($value, $data){
		$model = M('user_tuan_detail');
		$wdata['tid'] = $data['id'];
        $wdata['is_delete'] = 0;
		$num = $model->where($wdata)->count() ? : 0;
		return $num;
    }

    //搜索
    function _before_search(){
        $map = [];
        $map['is_delete'] = 0;
        if(I('keyword')){
            $map['company|company_no|contacts|tel'] = array('like','%'.I('keyword').'%');
        }
        $post = I('post.');
        $start_time = $post['start_time'];
        $end_time = $post['end_time'];
        if(!empty($start_time) || !empty($end_time)){
            if(empty($start_time)){
                $start_time = date('Y-m-d H:i:s',time());
            }
            if(empty($end_time)){
                $end_time =  date('Y-m-d H:i:s',time());
            }
            $start_time = strtotime($start_time);
            $end_time = strtotime($end_time);
            $map['add_time'] = array('between',[$start_time,$end_time]);
        }
        
        return $map;
    }


}